package wx.util;

import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import wx.Common.AccessTokenInfo;
import wx.web.servlet.WxServlet;

import javax.print.attribute.standard.JobName;

/**
 * Created by 76062 on 2017/10/11.
 */
public class WxUtil {


    public static JSONObject getWechatUserInfo(String openId, String taken) {
        String url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + taken + "&openid=" + openId;
        JSONObject result = null;
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(url);
        try {
            client.executeMethod(get);
            String returnJson = get.getResponseBodyAsString();
            returnJson = new String(returnJson.getBytes("ISO8859_1"), "UTF-8");
            result = JSONObject.fromObject(returnJson);

            if (result.containsKey("nickname"))
                return result;
            else
                return result;
        } catch (Exception e) {
        }

        return result;
    }

    public static void main(String[] args) {
//        JSONObject jsonObject = WxUtil.getWechatUserInfo("opA4t0bme5MTJMsu2ZGsSqjru9AM", AccessTokenInfo.accessToken);
//        System.out.println(jsonObject.get("nickname"));
    }

}
